layui.use(['table', 'element', 'jquery',], function () {
    var element = layui.element;
    var table = layui.table;
    var $ = layui.jquery;

    var tmp = {
        "msg": "操作成功",
        "code": 0,
        "data": [{
            "name": "2022-09-18 23:12:31",
            "value": ["2022-09-18 23:12:31", 37.68]
        }, {"name": "2022-09-19 10:12:10", "value": ["2022-09-19 10:12:10", 38.01]}, {
            "name": "2022-09-19 11:12:11",
            "value": ["2022-09-19 11:12:11", 39.14]
        }, {"name": "2022-09-19 12:12:12", "value": ["2022-09-19 12:12:12", 35.92]}, {
            "name": "2022-09-19 13:12:13",
            "value": ["2022-09-19 13:12:13", 35.51]
        }, {"name": "2022-09-19 14:12:14", "value": ["2022-09-19 14:12:14", 35.5]}, {
            "name": "2022-09-19 15:12:15",
            "value": ["2022-09-19 15:12:15", 36.01]
        }, {"name": "2022-09-19 15:12:16", "value": ["2022-09-19 15:12:16", 37.08]}, {
            "name": "2022-09-19 15:12:17",
            "value": ["2022-09-19 15:12:17", 37.23]
        }, {"name": "2022-09-19 15:12:18", "value": ["2022-09-19 15:12:18", 39.35]}, {
            "name": "2022-09-19 15:12:19",
            "value": ["2022-09-19 15:12:19", 35.48]
        }, {"name": "2022-09-19 15:12:20", "value": ["2022-09-19 15:12:20", 41.05]}, {
            "name": "2022-09-19 15:12:21",
            "value": ["2022-09-19 15:12:21", 38.27]
        }, {"name": "2022-09-19 15:12:22", "value": ["2022-09-19 15:12:22", 35.81]}, {
            "name": "2022-09-19 15:12:23",
            "value": ["2022-09-19 15:12:23", 40.91]
        }, {"name": "2022-09-19 16:12:24", "value": ["2022-09-19 16:12:24", 36.88]}, {
            "name": "2022-09-19 17:12:25",
            "value": ["2022-09-19 17:12:25", 37.67]
        }, {"name": "2022-09-19 18:12:26", "value": ["2022-09-19 18:12:26", 41.4]}, {
            "name": "2022-09-19 19:12:27",
            "value": ["2022-09-19 19:12:27", 35.95]
        }, {"name": "2022-09-19 20:12:28", "value": ["2022-09-19 20:12:28", 38.43]}, {
            "name": "2022-09-19 21:12:29",
            "value": ["2022-09-19 21:12:29", 41.19]
        }, {"name": "2022-09-19 22:12:30", "value": ["2022-09-19 22:12:30", 41.93]}, {
            "name": "2022-09-19 23:12:31",
            "value": ["2022-09-19 23:12:31", 36.1]
        }, {"name": "2022-09-20 10:12:10", "value": ["2022-09-20 10:12:10", 40.49]}, {
            "name": "2022-09-20 11:12:11",
            "value": ["2022-09-20 11:12:11", 37.79]
        }, {"name": "2022-09-20 12:12:12", "value": ["2022-09-20 12:12:12", 36.55]}, {
            "name": "2022-09-20 13:12:13",
            "value": ["2022-09-20 13:12:13", 41.26]
        }, {"name": "2022-09-20 14:12:14", "value": ["2022-09-20 14:12:14", 39.33]}, {
            "name": "2022-09-20 15:12:15",
            "value": ["2022-09-20 15:12:15", 36.19]
        }, {"name": "2022-09-20 15:12:16", "value": ["2022-09-20 15:12:16", 38.78]}, {
            "name": "2022-09-20 15:12:17",
            "value": ["2022-09-20 15:12:17", 39.26]
        }, {"name": "2022-09-20 15:12:18", "value": ["2022-09-20 15:12:18", 39.14]}, {
            "name": "2022-09-20 15:12:19",
            "value": ["2022-09-20 15:12:19", 38.14]
        }, {"name": "2022-09-20 15:12:20", "value": ["2022-09-20 15:12:20", 36.16]}, {
            "name": "2022-09-20 15:12:21",
            "value": ["2022-09-20 15:12:21", 35.84]
        }, {"name": "2022-09-20 15:12:22", "value": ["2022-09-20 15:12:22", 39.75]}, {
            "name": "2022-09-20 15:12:23",
            "value": ["2022-09-20 15:12:23", 40.86]
        }, {"name": "2022-09-20 16:12:24", "value": ["2022-09-20 16:12:24", 40.91]}, {
            "name": "2022-09-20 17:12:25",
            "value": ["2022-09-20 17:12:25", 41.94]
        }, {"name": "2022-09-20 18:12:26", "value": ["2022-09-20 18:12:26", 39.23]}, {
            "name": "2022-09-20 19:12:27",
            "value": ["2022-09-20 19:12:27", 41.47]
        }, {"name": "2022-09-20 20:12:28", "value": ["2022-09-20 20:12:28", 36.47]}, {
            "name": "2022-09-20 21:12:29",
            "value": ["2022-09-20 21:12:29", 37.51]
        }, {"name": "2022-09-20 22:12:30", "value": ["2022-09-20 22:12:30", 41.72]}, {
            "name": "2022-09-20 23:12:31",
            "value": ["2022-09-20 23:12:31", 35.95]
        }, {"name": "2022-09-21 10:12:10", "value": ["2022-09-21 10:12:10", 38.65]}, {
            "name": "2022-09-21 11:12:11",
            "value": ["2022-09-21 11:12:11", 40.88]
        }, {"name": "2022-09-21 12:12:12", "value": ["2022-09-21 12:12:12", 39.62]}, {
            "name": "2022-09-21 13:12:13",
            "value": ["2022-09-21 13:12:13", 35.15]
        }, {"name": "2022-09-21 14:12:14", "value": ["2022-09-21 14:12:14", 39.13]}, {
            "name": "2022-09-21 15:12:15",
            "value": ["2022-09-21 15:12:15", 40.49]
        }, {"name": "2022-09-21 15:12:16", "value": ["2022-09-21 15:12:16", 38.53]}, {
            "name": "2022-09-21 15:12:17",
            "value": ["2022-09-21 15:12:17", 39.12]
        }, {"name": "2022-09-21 15:12:18", "value": ["2022-09-21 15:12:18", 35.65]}, {
            "name": "2022-09-21 15:12:19",
            "value": ["2022-09-21 15:12:19", 41.17]
        }, {"name": "2022-09-21 15:12:20", "value": ["2022-09-21 15:12:20", 40.74]}, {
            "name": "2022-09-21 15:12:21",
            "value": ["2022-09-21 15:12:21", 38.15]
        }, {"name": "2022-09-21 15:12:22", "value": ["2022-09-21 15:12:22", 36.87]}, {
            "name": "2022-09-21 15:12:23",
            "value": ["2022-09-21 15:12:23", 36.29]
        }, {"name": "2022-09-21 16:12:24", "value": ["2022-09-21 16:12:24", 37.67]}, {
            "name": "2022-09-21 17:12:25",
            "value": ["2022-09-21 17:12:25", 39.18]
        }, {"name": "2022-09-21 18:12:26", "value": ["2022-09-21 18:12:26", 40.37]}, {
            "name": "2022-09-21 19:12:27",
            "value": ["2022-09-21 19:12:27", 41.11]
        }, {"name": "2022-09-21 20:12:28", "value": ["2022-09-21 20:12:28", 36.69]}, {
            "name": "2022-09-21 21:12:29",
            "value": ["2022-09-21 21:12:29", 36.01]
        }, {"name": "2022-09-21 22:12:30", "value": ["2022-09-21 22:12:30", 35.07]}, {
            "name": "2022-09-21 23:12:31",
            "value": ["2022-09-21 23:12:31", 39.99]
        }, {"name": "2022-09-22 10:12:10", "value": ["2022-09-22 10:12:10", 41.12]}, {
            "name": "2022-09-22 11:12:11",
            "value": ["2022-09-22 11:12:11", 37.87]
        }, {"name": "2022-09-22 12:12:12", "value": ["2022-09-22 12:12:12", 38.51]}, {
            "name": "2022-09-22 13:12:13",
            "value": ["2022-09-22 13:12:13", 36.59]
        }, {"name": "2022-09-22 14:12:14", "value": ["2022-09-22 14:12:14", 35.85]}, {
            "name": "2022-09-22 15:12:15",
            "value": ["2022-09-22 15:12:15", 38.04]
        }, {"name": "2022-09-22 15:12:16", "value": ["2022-09-22 15:12:16", 37.6]}, {
            "name": "2022-09-22 15:12:17",
            "value": ["2022-09-22 15:12:17", 35.36]
        }, {"name": "2022-09-22 15:12:18", "value": ["2022-09-22 15:12:18", 35.12]}, {
            "name": "2022-09-22 15:12:19",
            "value": ["2022-09-22 15:12:19", 36.1]
        }, {"name": "2022-09-22 15:12:20", "value": ["2022-09-22 15:12:20", 36.3]}, {
            "name": "2022-09-22 15:12:21",
            "value": ["2022-09-22 15:12:21", 40.95]
        }, {"name": "2022-09-22 15:12:22", "value": ["2022-09-22 15:12:22", 40.52]}, {
            "name": "2022-09-22 15:12:23",
            "value": ["2022-09-22 15:12:23", 35.83]
        }, {"name": "2022-09-22 16:12:24", "value": ["2022-09-22 16:12:24", 36.43]}, {
            "name": "2022-09-22 17:12:25",
            "value": ["2022-09-22 17:12:25", 41.6]
        }, {"name": "2022-09-22 18:12:26", "value": ["2022-09-22 18:12:26", 41.62]}, {
            "name": "2022-09-22 19:12:27",
            "value": ["2022-09-22 19:12:27", 35.37]
        }, {"name": "2022-09-22 20:12:28", "value": ["2022-09-22 20:12:28", 41.29]}, {
            "name": "2022-09-22 21:12:29",
            "value": ["2022-09-22 21:12:29", 35.52]
        }, {"name": "2022-09-22 22:12:30", "value": ["2022-09-22 22:12:30", 39.14]}, {
            "name": "2022-09-22 23:12:31",
            "value": ["2022-09-22 23:12:31", 39.28]
        }, {"name": "2022-09-24 10:12:10", "value": ["2022-09-24 10:12:10", 38.43]}, {
            "name": "2022-09-24 11:12:11",
            "value": ["2022-09-24 11:12:11", 35.64]
        }, {"name": "2022-09-24 12:12:12", "value": ["2022-09-24 12:12:12", 39.28]}, {
            "name": "2022-09-24 13:12:13",
            "value": ["2022-09-24 13:12:13", 37.29]
        }, {"name": "2022-09-24 14:12:14", "value": ["2022-09-24 14:12:14", 36.5]}, {
            "name": "2022-09-24 15:12:15",
            "value": ["2022-09-24 15:12:15", 39.96]
        }, {"name": "2022-09-24 15:12:16", "value": ["2022-09-24 15:12:16", 40.64]}, {
            "name": "2022-09-24 15:12:17",
            "value": ["2022-09-24 15:12:17", 35.43]
        }, {"name": "2022-09-24 15:12:18", "value": ["2022-09-24 15:12:18", 39.95]}, {
            "name": "2022-09-24 15:12:19",
            "value": ["2022-09-24 15:12:19", 36.62]
        }, {"name": "2022-09-24 15:12:20", "value": ["2022-09-24 15:12:20", 36.07]}, {
            "name": "2022-09-24 15:12:21",
            "value": ["2022-09-24 15:12:21", 39.84]
        }, {"name": "2022-09-24 15:12:22", "value": ["2022-09-24 15:12:22", 36.61]}, {
            "name": "2022-09-24 15:12:23",
            "value": ["2022-09-24 15:12:23", 41.1]
        }, {"name": "2022-09-24 16:12:24", "value": ["2022-09-24 16:12:24", 38.15]}, {
            "name": "2022-09-24 17:12:25",
            "value": ["2022-09-24 17:12:25", 38.72]
        }, {"name": "2022-09-24 18:12:26", "value": ["2022-09-24 18:12:26", 35.86]}, {
            "name": "2022-09-24 19:12:27",
            "value": ["2022-09-24 19:12:27", 39.08]
        }, {"name": "2022-09-24 20:12:28", "value": ["2022-09-24 20:12:28", 39.21]}, {
            "name": "2022-09-24 21:12:29",
            "value": ["2022-09-24 21:12:29", 41.12]
        }, {"name": "2022-09-24 22:12:30", "value": ["2022-09-24 22:12:30", 36.92]}, {
            "name": "2022-09-24 23:12:31",
            "value": ["2022-09-24 23:12:31", 36.68]
        }, {"name": "2022-09-25 10:12:10", "value": ["2022-09-25 10:12:10", 35.72]}, {
            "name": "2022-09-25 11:12:11",
            "value": ["2022-09-25 11:12:11", 41.86]
        }, {"name": "2022-09-25 12:12:12", "value": ["2022-09-25 12:12:12", 40.8]}, {
            "name": "2022-09-25 13:12:13",
            "value": ["2022-09-25 13:12:13", 35.83]
        }, {"name": "2022-09-25 14:12:14", "value": ["2022-09-25 14:12:14", 41.07]}, {
            "name": "2022-09-25 15:12:15",
            "value": ["2022-09-25 15:12:15", 39.58]
        }, {"name": "2022-09-25 15:12:16", "value": ["2022-09-25 15:12:16", 35.95]}, {
            "name": "2022-09-25 15:12:17",
            "value": ["2022-09-25 15:12:17", 35.83]
        }, {"name": "2022-09-25 15:12:18", "value": ["2022-09-25 15:12:18", 38.0]}, {
            "name": "2022-09-25 15:12:19",
            "value": ["2022-09-25 15:12:19", 35.64]
        }, {"name": "2022-09-25 15:12:20", "value": ["2022-09-25 15:12:20", 35.73]}, {
            "name": "2022-09-25 15:12:21",
            "value": ["2022-09-25 15:12:21", 36.41]
        }, {"name": "2022-09-25 15:12:22", "value": ["2022-09-25 15:12:22", 40.91]}, {
            "name": "2022-09-25 15:12:23",
            "value": ["2022-09-25 15:12:23", 38.24]
        }, {"name": "2022-09-25 16:12:24", "value": ["2022-09-25 16:12:24", 35.5]}, {
            "name": "2022-09-25 17:12:25",
            "value": ["2022-09-25 17:12:25", 41.94]
        }, {"name": "2022-09-25 18:12:26", "value": ["2022-09-25 18:12:26", 39.97]}, {
            "name": "2022-09-25 19:12:27",
            "value": ["2022-09-25 19:12:27", 36.23]
        }, {"name": "2022-09-25 20:12:28", "value": ["2022-09-25 20:12:28", 41.23]}, {
            "name": "2022-09-25 21:12:29",
            "value": ["2022-09-25 21:12:29", 39.31]
        }, {"name": "2022-09-25 22:12:30", "value": ["2022-09-25 22:12:30", 37.13]}, {
            "name": "2022-09-25 23:12:31",
            "value": ["2022-09-25 23:12:31", 41.46]
        }]
    };

    let arr = new Array();
    for (it in tmp.data) {
        arr.push([tmp.data[it].name, tmp.data[it].value[1]]);
    }
    //console.log(arr);

    var chart1 = echarts.init(document.getElementById('chart1')); //图表1
    var chart2 = echarts.init(document.getElementById('chart2')); //图表2
    var chart3 = echarts.init(document.getElementById('chart3')); //图表3

    var option1 = {
        title: {
            text: '动物品种分布',
            // subtext: '业务分布',
            left: 'center',
            top: '2%'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: '动物品种分布',
                type: 'pie',
                radius: '40%',
                center: ["50%", "60%"],
                data: [
                    {value: 1048, name: '南阳牛', itemStyle: {color: "#5971C0"},},
                    {value: 735, name: '蒙古牛', itemStyle: {color: "#9ECA7F"},},
                    {value: 580, name: '秦川牛', itemStyle: {color: "#F3C96B"},},
                    {value: 484, name: '鲁西牛', itemStyle: {color: "#DE6E6A"},},
                    {value: 899, name: '延边牛', itemStyle: {color: "#84BEDB"},}
                ],
                label: {
                    show: true,
                    position: "outside",
                    formatter: "{b} {c}（{d}%）",
                },
            }

        ]
    };

    var option2 = {
        title: {
            text: '在栏动物状态分析',
            // subtext: '工单分布',
            left: 'center',
            top: '2%'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: '在栏动物状态分析',
                type: 'pie',
                radius: '40%',
                center: ["50%", "60%"],
                data: [
                    {value: 1048, name: '健康在栏', itemStyle: {color: "#5971C0"},},
                    {value: 735, name: '疾病', itemStyle: {color: "#9ECA7F"},},
                    {value: 580, name: '发情', itemStyle: {color: "#F3C96B"},},
                    {value: 484, name: '近期生产', itemStyle: {color: "#DE6E6A"},},
                    {value: 899, name: '其他', itemStyle: {color: "#84BEDB"},}
                ],
                label: {
                    show: true,
                    position: "outside",
                    formatter: "{b} {c}（{d}%）",
                },
            }

        ]
    };

    var option3 = {
        tooltip: {
            trigger: 'axis',
            formatter: function (params) {
                return (
                    params[0].value[0] +
                    '    ' +
                    params[0].value[1] + '℃'
                );
            },
            axisPointer: {
                animation: false
            }
        },
        title: {
            text: '近7天动物体温分布',
            left: 'center',
            subtext: '最小体温：36.7  最大体温：40.23   平均体温：36.9',
            top: '2%'
        },
        xAxis: {
            type: 'time'
        },
        yAxis: {
            max: 70,
        },
        color: '#5971BF',
        series: [
            {
                type: 'scatter',
                symbolSize: 10,
                data: arr,
                markLine: {
                    animation: false,
                    lineStyle: {
                        type: 'solid'
                    },
                    data: [
                        [
                            {
                                coord: [1, 35],
                                symbol: 'none'
                            },
                            {
                                coord: [7, 35],
                                symbol: 'none'
                            },
                            // {type: 'max', name: '最大值'},
                            // {type: 'min', name: '最小值'}
                        ]
                    ]
                }
            }
        ]
    };

    option1 && chart1.setOption(option1);
    option2 && chart2.setOption(option2);
    option3 && chart3.setOption(option3);

    window.addEventListener("resize", function () {
        chart1.resize();
        chart2.resize();
        chart3.resize();
    });

    var $table1 = table.render({
        elem: '#table1',
        id: 'table1',
        page: true, //开启分页
        limit: 5,
        limits: [5, 10, 20, 50],
        cols: [[ //表头

            {field: 'baseStationNum', title: '基站号', align: 'center', minWidth: 80},
            {field: 'num', title: '芯片号', align: 'center', minWidth: 80},
            {
                field: 'warningType', title: '预警类型', align: 'center', minWidth: 80, templet: function (d) {
                    return top.sys.dictName('warning_type', d.warningType);
                }
            },
            {field: 'warningDesc', title: '预警信息', align: 'center', minWidth: 80},
            {field: 'warningTime', title: '预警时间', align: 'center', minWidth: 80},
            {
                field: 'deptId', title: '所属养殖户', align: 'center', minWidth: 80, templet: function (d) {
                    return top.sys.deptName(d.deptId);
                }
            }
        ]],
        // data: tableData,
        url: "/animal/warningRecord/list",
        skin: 'nob',
        even: true,
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": 0, //解析接口状态
                //"msg": res.message, //解析提示文本
                "count": res.total, //解析数据长度
                "data": res.rows //解析数据列表
            };
        },
        where: {
            offset: table1Offset
        }
    });

    var table2 = table.render({
        elem: '#table2',
        id: 'table2',
        // url: '', //数据接口
        page: true, //开启分页
        limit: 5,
        limits: [5, 10, 20, 50],
        cols: [[ //表头
            {field: 'baseStationNum', title: '基站号', align: 'center', minWidth: 80},
            {field: 'baseStationModel', title: '设备型号', align: 'center', minWidth: 80},
            {
                field: 'status', title: '工作状态', align: 'center', minWidth: 80, templet: function (d) {
                    return top.sys.dictName('base_station_status', d.status);
                }
            },
            {field: 'createTime', title: '加入时间', align: 'center', minWidth: 80},
            {
                field: 'deptId', title: '所属养殖户', align: 'center', minWidth: 80, templet: function (d) {
                    return top.sys.deptName(d.deptId);
                }
            }
        ]],
        // data: tableData,
        url: "/animal/baseStation/list",
        skin: 'nob',
        even: true,
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": 0, //解析接口状态
                //"msg": res.message, //解析提示文本
                "count": res.total, //解析数据长度
                "data": res.rows //解析数据列表
            };
        },
        where: {
            offset: table2Offset
        },
        beforeSend: function (request) {
            console.log(request);
        }
    });

    function table1Offset() {
        var length = $(".table1 .layui-laypage-skip").find("input").val();
        if (length == null) {
            length = 1;
        }
        return (length - 1) * 5;
    }

    function table2Offset() {
        var length = $(".table2 .layui-laypage-skip").find("input").val();
        if (length == null) {
            length = 1;
        }
        return (length - 1) * 5;
    }
});

